package com.itheima.aimobile.domain;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class JsonRuleRepository {
    private final VectorStore vectorStore;

    @PostConstruct
    public void init() {
        // 向量化并存储
        Resource resource = new ClassPathResource("rules.json");
        JsonReader jsonReader = new JsonReader(resource, "description");
        List<Document> documents = jsonReader.get();
        vectorStore.add(documents);
    }
}
